package com.doujiang.bus.service.impl;

import com.doujiang.bus.domain.Customer;
import com.doujiang.bus.mapper.CustomerMapper;
import com.doujiang.bus.service.ICustomerService;
import com.doujiang.bus.vo.CustomerVo;
import com.doujiang.sys.utils.DataGridView;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：豆浆
 * @name :CustomerServiceImpl
 * @Date：2023/12/19 15:24
 */
@Service
public class CustomerServiceImpl implements ICustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 查询所有客户信息 分⻚pagehelper
     * @param customerVo
     * @return
     */
    @Override
    public DataGridView queryAllCustomer(CustomerVo customerVo) {
        //查询所有客户信息 分⻚查询pagehelper
        //PageHelper是一个流行的MyBatis分页插件
        Page<Object> page = PageHelper.startPage(customerVo.getPage(),customerVo.getLimit());
        List<Customer> data = customerMapper.queryAllCustomer(customerVo);
        //查询的结果是一个Customer对象的列表
        return new DataGridView(page.getTotal(),data);
    }

    /*
     * 添加客户信息
     * */
    @Override
    public void addCustomer(CustomerVo customerVo) {

        customerMapper.insertSelective(customerVo);
    }
    /*
     * 删除用户
     * */
    @Override
    public void deleteCustomer(String identity) {
        customerMapper.deleteCostomer(identity);
    }
    /*
     * 修改用户信息
     * */
    @Override
    public void updateCustomer(CustomerVo customerVo) {
        customerMapper.updateCostomer(customerVo);
    }

    /*
    * 批量删除用户
    * */
    @Override
    public void deleteBatchCustomer(String[] identitys) {
        for (String identity : identitys) {
            this.deleteCustomer(identity);
        }
    }

    //身份证号码查询客户
    @Override
    public Customer queryCustomerByIdentity(String identity) {
        return customerMapper.selectByPrimaryKey(identity);
    }

}
